package cn.kgc.crowdfundingadmin.service;


import cn.kgc.crowdfundingadmin.mapper.CertMapper;
import cn.kgc.crowdfundingadmin.pojo.Cert;
import cn.kgc.crowdfundingadmin.pojo.CertExample;
import cn.kgc.crowdfundingadmin.pojo.Role;
import cn.kgc.crowdfundingadmin.pojo.RoleExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Scope
@Service("certService")
public class CertServiceImpl implements CertService {
    @Resource
    CertMapper certMapper;

    @Override
    public void updateCert(Cert cert) {
        certMapper.updateByPrimaryKey(cert);
    }

    @Override
    public void saveCert(String certName) {
        certMapper.insert(new Cert(null, certName));
    }

    @Override
    public void batchRemove(List<Integer> certIdList) {
        CertExample certExample = new CertExample();

        certExample.createCriteria().andIdIn(certIdList);

        certMapper.deleteByExample(certExample);
    }

    @Override
    public List<Cert> getCertListByIdList(List<Integer> certIdList) {
        // 创建实体类Role对应的Example对象
        CertExample certExample = new CertExample();

        // 在Example对象中封装查询条件
        certExample.createCriteria().andIdIn(certIdList);

        // 执行查询
        return certMapper.selectByExample(certExample);
    }

    @Override
    public PageInfo<Cert> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
        // 1.开启分页功能
        PageHelper.startPage(pageNum, pageSize);

        // 2.执行查询
        CertExample certExample=new CertExample();
        CertExample.Criteria criteria = certExample.createCriteria();
        criteria.andNameLike("%"+keyword+"%");
        List<Cert> list = certMapper.selectByExample(certExample);
        // 3.封装为PageInfo对象
        return new PageInfo<>(list);
    }

    @Override
    public int countByExample(CertExample example) {
        return 0;
    }

    @Override
    public int deleteByExample(CertExample example) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return 0;
    }

    @Override
    public int insert(Cert record) {
        return 0;
    }

    @Override
    public int insertSelective(Cert record) {
        return 0;
    }

    @Override
    public List<Cert> selectByExample(CertExample example) {
        return null;
    }

    @Override
    public Cert selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public int updateByExampleSelective(Cert record, CertExample example) {
        return 0;
    }

    @Override
    public int updateByExample(Cert record, CertExample example) {
        return 0;
    }

    @Override
    public int updateByPrimaryKeySelective(Cert record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Cert record) {
        return 0;
    }
}